﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ComputerArchitecture.Core;
using ComputerArchitecture.Core.Logging;
using ComputerArchitecture.Numbers;
using ComputerArchitecture.Units.Interfaces;

namespace ComputerArchitecture.Units.Float
{
    public class FloatSubstractUnit : LoggingObject, IFloatSubstractUnit
    {
        #region Fields

        private readonly IFloatAdderUnit _floatAdderUnit;
        private readonly IFloatNegateUnit _floatNegateUnit;

        #endregion

        #region Constructors

        public FloatSubstractUnit(ILoggingService loggingService, IFloatAdderUnit floatAdderUnit, IFloatNegateUnit floatNegateUnit)
            : base(loggingService)
        {
            ArgumentValidator.NullValidate(floatAdderUnit);
            _floatAdderUnit = floatAdderUnit;
            ArgumentValidator.NullValidate(floatNegateUnit);
            _floatNegateUnit = floatNegateUnit;
        }

        public FloatSubstractUnit(ILoggingService loggingService)
            : this(loggingService, new FloatAdderUnit(loggingService), new FloatNegateUnit(loggingService))
        {
        }

        #endregion

        #region Methods

        public IFloatPointNumber Substract(IFloatPointNumber first, IFloatPointNumber second)
        {
            IFloatPointNumber negateSecond = _floatNegateUnit.Negate(second);
            return _floatAdderUnit.Add(first, negateSecond);
        }

        #endregion
    }
}
